﻿namespace _01_Tower3._0
{
    internal class Character
    {
        public string? Name { get; }
        public int Hp { get; protected set; }
        public int Mp { get; }
        public int Atk { get; protected set; }
        public int Def { get; protected set; }

        public bool IsDead { get; private set; }

        public int DialogId;
        public Map map;

        protected Character(string name, int hp, int mp, int atk, int def, Map map, int dialogId = -1)
        {
            this.map = map;

            Name = name;
            Hp = hp;
            Mp = mp;
            Atk = atk;
            Def = def;
            IsDead = false;
            DialogId = dialogId;
        }

        public void Attack(Character target)
        {
            if (Atk > target.Def)
            {
                InfoSystem.Instance.AddInfo($"{Name}攻击了{target.Name}!", ConsoleColor.Green);
                target.TakeDamage(Atk - target.Def);
            }
            else
            {
                InfoSystem.Instance.AddInfo($"{Name}攻击了{target.Name},攻击无效!");
            }
        }

        void TakeDamage(int damage)
        {
            InfoSystem.Instance.AddInfo($"{Name}受到了{damage}点伤害!", ConsoleColor.Yellow);
            Hp -= damage;
            if (Hp < 0)
            {
                Hp = 0;
            }
            // 死亡判定
            IsDead = Hp == 0;
            if (IsDead)
            {
                InfoSystem.Instance.AddInfo($"{Name}死亡!", ConsoleColor.Red);
            }
        }
    }
}
